<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>专属二维码</title>
    <link href="../style/base.css" rel="stylesheet" type="text/css">

    <script src="https://cdn.bootcss.com/jquery/3.2.0/jquery.min.js"></script>
    <script type="text/javascript" src="../js/paramsTool.js"></script>

</head>
<style>

</style>
<script type="text/javascript">
    var host = window.location.origin;

    if(host == 'http://weblogin.178dn.net') host = 'http://disa.178dn.net';

    var params = queryString();
    console.log('params:',JSON.stringify(params));
    var disOpenid = null,disUid = null;
    if(params.referee){
        disOpenid = params.referee
    }else {
        disOpenid = getCookie('disOpenid')
    }
    if(params.disUid){
        disUid = params.disUid
    }else {
        disUid = getCookie('disUid');
    }

    if(!disOpenid || !disUid){
        getDisWxCode();
    }

    var height = window.innerHeight;
    var imgPath = '../disQR/' + disUid + '.png';
    $(document).ready(function() {
        $('#img').attr('src',imgPath).css({width:'100%',height:height,position:'fixed'});
    });
    function createCode(){
        $.ajax({
            url: host+ "/createDisQR",
            type: "get",
            dataType:'json',
            headers: {"content-type":"application/json","disuid":disUid,'disopenid':disOpenid},
            success:function(data){
                if(data.code){
                    alert(data.info);
                }else {
                    $("#img").remove();
                    var canvas = $("<canvas id='canvas'></canvas>").appendTo('body');
                    canvas =document.getElementById('canvas');
                    console.log('canvas:',canvas);
                    var ctx = canvas.getContext("2d");
                    canvas.width = window.innerWidth;
                    canvas.height = height;
                    var img =new Image();
                    img.src=imgPath;
                    img.onload = function () {              //图片加载完再操作,不然不会显示,再去写字,文字也是,要在图片后面写,不然会被挡住
                        ctx.drawImage(img,0,0,canvas.width,canvas.height);
                        ctx.fillStyle= "#F1E70E"; //文字颜色
                        ctx.font="22px Georgia";
//                    ctx.shadowColor = 'rgba(0, 0, 0, 0.5)';
                        // 将阴影向右移动15px，向上移动10px
                        ctx.shadowOffsetX = 15;
                        ctx.shadowOffsetY = -10;
                        // 轻微模糊阴影
                        ctx.shadowBlur = 2;
                        ctx.fillText("ID:"+disUid,10,25);
                        ctx.restore();
                    }
                }
            },
            error:function() {
                location.reload();
            }

        });

    }

</script>
<body>
<img id="img" onerror='createCode()'>
</body>
</html>